﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace RobotGameData
{
    public class FightingRobot : Character
    {
        public FightingRobot()
        {
        }

        public FightingRobot(Vector2 startLocation, Vector2 frameSize, int framesPerDirection)
        {
            Position = startLocation;
            FrameSize = frameSize;
            Origin = frameSize / 2;
            FrameLength = 0.05f;
            MaxFramesPerDirection = framesPerDirection;
            Direction = Direction.South;
            Speed = 5f;
          
        }
      
        public void HandleInput(InputState input)
        {
            Vector2 playerMovement = Vector2.Zero;

            if (input.IsNewKeyPress(Keys.D))
            {
                playerMovement.X = -1;
            }
            else if (input.IsNewKeyPress(Keys.A))
            {
                playerMovement.X = 1;
            }
            if (input.IsNewKeyPress(Keys.W))
            {
                playerMovement.Y = -1;
            }
            else if (input.IsNewKeyPress(Keys.S))
            {
                playerMovement.Y = 1;
            }

            if (playerMovement != Vector2.Zero)
            {
                playerMovement.Normalize();
            }


            if (playerMovement == Vector2.Zero)
                IsAnimating = false;
            else
                IsAnimating = true;

            if (playerMovement.X > 0 && playerMovement.Y == 0) Direction = Direction.East;
            if (playerMovement.X < 0 && playerMovement.Y == 0) Direction = Direction.West;
            if (playerMovement.X == 0 && playerMovement.Y > 0) Direction = Direction.South;
            if (playerMovement.X == 0 && playerMovement.Y < 0) Direction = Direction.North;
            if (playerMovement.X < 0 && playerMovement.Y < 0) Direction = Direction.NorthWest;
            if (playerMovement.X < 0 && playerMovement.Y > 0) Direction = Direction.SouthWest;
            if (playerMovement.X > 0 && playerMovement.Y < 0) Direction = Direction.NorthEast;
            if (playerMovement.X > 0 && playerMovement.Y > 0) Direction = Direction.SouthEast;

            Position += Speed * playerMovement;

            LastMovement = Speed * playerMovement;
        }
    }
}
